const { DataTypes, fn } = require("sequelize");

const seq = require("../db/seq");

const Answer = seq.define(
  "answer",
  {
    id: {
      type: DataTypes.UUID,
      allowNull: false,
      defaultValue: DataTypes.UUIDV4, // 或 DataTypes.UUIDV1
      primaryKey: true,
      comment: "id，主键，uuid格式",
    },
    question_id: {
      type: DataTypes.UUID,
      allowNull: false,
      comment: "问卷id，uuid格式",
    },
    answers: {
      type: DataTypes.JSON,
      allowNull: false,
      comment: "答卷对象",
    },
  },
  {
    timestamps: true,
    createdAt: "createdAt",
    updatedAt: "updatedAt",
  }
);

// 初始化模型
async function initModel() {
  await Answer.sync({ alter: true });
}

// initModel();

module.exports = Answer;
